#ifndef _BUSINESSSERVICE_H
#define _BUSINESSSERVICE_H
#include "task.hpp"
#include "TcpConnection.hpp"
#include "Packet.hpp"
#include "ffmpeg.hpp"
#include <iostream>
#include <string>
#include <thread>
#include <memory>
using std::thread;
using std::shared_ptr;
using std::cout;
using std::endl;
using std::string;

class businessService:public task
{
public:
    businessService(const string & msg,TcpConnection & conn):_msg(msg),_conn(conn) {}
    void process(void *ptr = nullptr) override{
        cout<<"encode."<<endl;
        cout<<"compute."<<endl;
        cout<<"decode."<<endl;

        string respone = "thanks!i have recieved your msg.";
        _conn.sendInLoop(respone);
    }
    ~businessService() {}

private:
    string _msg;
    TcpConnection & _conn;
};
enum TaskType{
    TTR1 = 1,
    TTR1RPOK,
    TTR1RPERR,
    TTR2,
    TTR2RPOK,
    TTR2RPERR,
    TTLS1,
    TTLS1RPOK,
    TTLS1RPERR,
    TTLS2,
    TTLS2RPOK,
    TTLS2RPERR,
    TASK_GET_CODEC_PARAMS,
    TASK_GET_CODEC_PARAMS_RESP_OK,
    TASK_GET_CODEC_PARAMS_RESP_ERROR,
    TASK_GET_AVPACKET,
    TASK_GET_AVPACKET_RESP_OK,
    TASK_GET_AVPACKET_RESP_ERROR,
    TASK_GET_AUDIO_CODEC_PARAMS_RESP_OK, // 回复音频解码器参数
    TASK_STOP_RTMP, // 停止查看RTMP实时流
    TASK_PTZ_CONTROL,
    TASK_PTZ_CONTROL_RESP_OK,
    TASK_PTZ_CONTROL_RESP_ERROR,//以上功能完成
    TASK_GET_PLAYBACK_RANGE,//25，获取服务器持有的录像文件时间范围
    TASK_GET_PLAYBACK_RANGE_OK,
    TASK_GET_PLAYBACK_RANGE_ERROR,
    TASK_GET_PLAYBACK_AVPACKET,//查看回放
    TASK_GET_PALYBACK_CODEC_PARAMS, // 请求回放音视频解码器参数
    TASK_STM32_SENSORS,
};

class UserLoginSection1:public task{
public:
    UserLoginSection1(Packet && packet,TcpConnection & conn):_packet(std::move(packet)),_conn(conn) {}
    void process(void *ptr = nullptr) override;
private:
    Packet _packet;
    TcpConnection & _conn;
};

class UserLoginSection2:public task{
public:
    UserLoginSection2(Packet && packet,TcpConnection & conn):_packet(std::move(packet)),_conn(conn) {}
    void process(void *ptr = nullptr) override;
private:
    Packet _packet;
    TcpConnection & _conn;
};


class UserRegister1:public task{
public:
    UserRegister1(Packet && packet,TcpConnection & conn):_packet(std::move(packet)),_conn(conn) {}
    void process(void *prt = nullptr)override;
private:
    string GenRandomString(int length);
    Packet _packet;
    TcpConnection & _conn;
    string preWay = "$1$";
    int saltLen = 8;
};
class UserRegister2:public task{
public:
    UserRegister2(Packet && packet,TcpConnection & conn):_packet(std::move(packet)),_conn(conn) {}
    void process(void *prt = nullptr)override;
private:
    Packet _packet;
    TcpConnection & _conn;
};


class SendCodecParams:public task{
public:
    SendCodecParams(Packet && packet,TcpConnection & conn):_packet(std::move(packet)),_conn(conn) {}
    void process(void *prt = nullptr)override;
private:
    Packet _packet;
    TcpConnection & _conn;
};

class SendAVPacket:public task{
public:
    SendAVPacket(TcpConnection & conn,RtspDecoder * rtspdecoder,map<int,RtspDecoder> &ffmpegs):_conn(conn),_rtspd(rtspdecoder),_ffmpegs(ffmpegs) {}
    void process(void *prt = nullptr)override;
private:
    TcpConnection & _conn;
    RtspDecoder * _rtspd;
    map<int,RtspDecoder> &_ffmpegs;
};

class SendPTZControl:public task{
public:
    SendPTZControl(Packet && packet,TcpConnection & conn):_packet(std::move(packet)),_conn(conn) {}
    void process(void *prt = nullptr)override;
private:
    Packet _packet;
    TcpConnection & _conn;
};

class RecordVideo:public task{
public:
    RecordVideo(const string & url, int cameraId, int channel,const string & camera_serial_no):_url(url),_cameraId(cameraId),_channel(channel),_camera_serial_no(camera_serial_no){}
    void process(void * prt = nullptr)override;
private:
    string _url;
    int _cameraId;
    int _channel;
    string _camera_serial_no;
};

//回看播放列表，时间的发送
class SendPlayList:public task{
public:
    SendPlayList(Packet && packet,TcpConnection & conn):_packet(std::move(packet)),_conn(conn) {}
    void process(void *prt = nullptr)override;
private:
    Packet _packet;
    TcpConnection & _conn;
};

//发送解码器参数
class SendPlayBackCodecParams:public task{
public:
    SendPlayBackCodecParams(Packet && packet,TcpConnection & conn):_packet(std::move(packet)),_conn(conn) {}
    void process(void *prt = nullptr)override;
private:
    Packet _packet;
    TcpConnection & _conn;
};
class SendPlayBackAVPacket:public task{
public:
    SendPlayBackAVPacket(Packet && packet,TcpConnection & conn,RtspDecoder * rtspdecoder,map<int,RtspDecoder> &ffmpegs):_packet(std::move(packet)),_conn(conn),_rtspd(rtspdecoder),_ffmpegs(ffmpegs) {}
    void process(void *prt = nullptr)override;
private:
    Packet _packet;
    TcpConnection & _conn;
    RtspDecoder * _rtspd;
    map<int,RtspDecoder> &_ffmpegs;
};

class SendStm32Infm:public task{
public:
    SendStm32Infm(Packet && packet):_packet(std::move(packet)) {}
    void process(void *prt = nullptr)override;
private:
    Packet _packet;
    
};


#endif



